if !CLIENT then return end -- hud is for the client only.

module('hud', package.seeall)

local HideElements = {"CHudHealth"}

local TimeLeft = Material("flood/timeleft")
local HeartHP = Material("flood/heart")

-- This draws our entire hud!
function Draw()
	surface.SetDrawColor(255, 255, 255, 255)
	surface.SetMaterial(TimeLeft)
    surface.DrawTexturedRect(ScrW()/2-128, 8, 256, 64)
	
	draw.SimpleTextOutlined(string.ToMinutesSeconds(round.RemainingTime()), "Flood30", ScrW()/2, 38, colour_black, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, 0, colour_black)
	
	-- HP
	local hearts = math.ceil(LocalPlayer():Health()/25)
	
	render.SetScissorRect(8, ScrH()-72, 72, ScrH()-8, true)
	
	surface.SetDrawColor(255, 255, 255, 255)
	surface.SetMaterial(HeartHP)
	if hearts == 0 then
		surface.DrawTexturedRect(-248, ScrH()-74, 512, 64)
	elseif hearts == 1 then
		surface.DrawTexturedRect(-184, ScrH()-74, 512, 64)
	elseif hearts == 2 then
		surface.DrawTexturedRect(-120, ScrH()-74, 512, 64)
	elseif hearts == 3 then
		surface.DrawTexturedRect(-56, ScrH()-74, 512, 64)
	elseif hearts == 4 then
		surface.DrawTexturedRect(8, ScrH()-74, 512, 64)
	end
	
	render.SetScissorRect(0, 0, 0, 0, false)
end

function Update()
	vgui.GetWorldPanel():SetCursor("blank") -- hide the default cursor.
end

hook.Add("HUDShouldDraw", "Flood_HideOldHUD", function(element)
	if table.HasValue(HideElements, element) then return false end
end)